$('#cancel').click(function() {
	$('.view').css('display', 'none')
})


$('.add_view').click(function() {
	$('.add_view_pop').css('display', 'block')
})

$('.add_view_pop #save').click(function() {
	$('.add_view_pop').css('display', 'none')
})




layui.use('element', function() {
	var element = layui.element;
})
//网谈日期范围
layui.use('laydate', function() {
	var laydate = layui.laydate;
	laydate.render({
		elem: '#test6',
		range: true
	})
});
//个人添加日期范围
layui.use('laydate', function() {
	var laydate = layui.laydate;
	laydate.render({
		elem: '#test7',
		range: true
	})
});
//留言日期范围
layui.use('laydate', function() {
	var laydate = layui.laydate;
	laydate.render({
		elem: '#test8',
		range: true
	})
});
//批量日期范围
layui.use('laydate', function() {
	var laydate = layui.laydate;
	laydate.render({
		elem: '#test9',
		range: true
	})
});

layui.use('form', function() {
	var form = layui.form;
	//			form.on('submit(formDemo)', function(data) {
	//				layer.msg(JSON.stringify(data.field));
	//				return false;
	//			});
});

layui.use(['jquery', 'layer'], function() {
	var $ = layui.$ //重点处
		,
		layer = layui.layer;
});
//网谈table
layui.use('table', function() {
	var table = layui.table;
	//监听表格复选框选择
	table.on('checkbox(demo)', function(obj) {
		console.log(obj)
	});
	//监听工具条
	table.on('tool(demo1)', function(obj) {
		var data = obj.data;
		if(obj.event === 'edit') {
			$('.view').css('display', 'block')
			//			layer.alert('编辑行：<br><input type="text">' + JSON.stringify(data))
		} else if(obj.event === 'del') {
			layer.confirm('真的删除行么', function(index) {
				obj.del();
				layer.close(index);
			});
		}
	});
	//搜索功能
	var $ = layui.$,
		active = {
			reload: function() {
				var demoReload = $('#demoReload');

				//执行重载
				table.reload('idTest', {
					page: {
						curr: 1 //重新从第 1 页开始
					},
					where: {
						key: {
							id: demoReload.val()
						}
					}
				});
			}
		};

	$('.demoTable .layui-btn').on('click', function() {
		var type = $(this).data('type');
		active[type] ? active[type].call(this) : '';
	});
});

layui.use('upload', function() {
	var $ = layui.jquery,
		upload = layui.upload;

	//普通图片上传
	var uploadInst = upload.render({
		elem: '#test1',
		url: '/upload/',
		before: function(obj) {
			//预读本地文件示例，不支持ie8
			obj.preview(function(index, file, result) {
				$('#demo1').attr('src', result); //图片链接（base64）
			});
		},
		done: function(res) {
			//如果上传失败
			if(res.code > 0) {
				return layer.msg('上传失败');
			}
			//上传成功
		},
		error: function() {
			//演示失败状态，并实现重传
			var demoText = $('#demoText');
			demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
			demoText.find('.demo-reload').on('click', function() {
				uploadInst.upload();
			});
		}
	});
});